// 简单的token测试
export const simpleTokenTest = () => {
  console.log('🧪 开始简单token测试...')
  
  // 1. 清除所有existing数据
  localStorage.removeItem('token')
  localStorage.removeItem('tokenData')
  localStorage.removeItem('user')
  
  console.log('1️⃣ 清除localStorage完成')
  
  // 2. 手动设置tokenData
  const testTokenData = {
    token: 'test-token-123',
    expiresAt: Date.now() + (24 * 60 * 60 * 1000), // 24小时后过期
    refreshToken: 'refresh-123'
  }
  
  const testUser = {
    id: 1,
    uuid: 'test-uuid',
    username: 'testuser',
    email: 'test@example.com',
    subscriptionType: 'free'
  }
  
  localStorage.setItem('tokenData', JSON.stringify(testTokenData))
  localStorage.setItem('user', JSON.stringify(testUser))
  
  console.log('2️⃣ 手动设置localStorage完成')
  console.log('  tokenData:', localStorage.getItem('tokenData'))
  console.log('  user:', localStorage.getItem('user'))
  
  // 3. 尝试重新加载页面模拟
  console.log('3️⃣ 模拟页面重新加载...')
  
  // 重新初始化userStore
  import('@/stores/user').then(({ useUserStore }) => {
    const userStore = useUserStore()
    
    console.log('4️⃣ 重新初始化userStore前的状态:')
    console.log('  isAuthenticated:', userStore.isAuthenticated)
    console.log('  token:', userStore.token)
    console.log('  user:', userStore.user)
    console.log('  tokenData:', userStore.tokenData)
    
    // 手动调用initUser
    userStore.initUser()
    
    console.log('5️⃣ 调用initUser后的状态:')
    console.log('  isAuthenticated:', userStore.isAuthenticated)
    console.log('  token:', userStore.token)
    console.log('  user:', userStore.user)
    console.log('  tokenData:', userStore.tokenData)
    
    if (userStore.isAuthenticated) {
      console.log('✅ Token测试成功！用户状态已恢复')
    } else {
      console.log('❌ Token测试失败！用户状态未恢复')
    }
  })
}

// 导出到全局
if (typeof window !== 'undefined') {
  ;(window as any).simpleTokenTest = simpleTokenTest
  console.log('🔧 简单token测试已加载: simpleTokenTest()')
}
